#include "filerw.h" 

MY_FILE* _fopen(const char* filename,const char* mode)
{
    MY_FILE * file = (MY_FILE*)malloc(sizeof(MY_FILE));
    if(!file) return NULL;
    if(!strcmp(mode,"w"))
    {
        file->fileno = open(filename,O_WRONLY|O_CREAT|O_TRUNC,MODE);
        if(file->fileno < 0)
        {
            free(file);
            return NULL;
        }
        file->outpos = 0;
    }
    else if(!strcmp(mode,"rw"))
    {

        file->fileno = open(filename,O_WRONLY|O_CREAT|O_TRUNC,MODE);
        if(file->fileno < 0)
        {
            free(file);
            return NULL;
        }
        file->outpos = 0;
    }
    else if(!strcmp(mode,"r"))
    {

        file->fileno = open(filename,O_RDONLY);
        if(file->fileno < 0)
        {
            free(file);
            return NULL;
        }
        file->outpos = 0;
    }
    else if(!strcmp(mode,"a"))
    {

        file->fileno = open(filename,O_WRONLY|O_CREAT|O_TRUNC|O_APPEND,MODE);
        if(file->fileno < 0)
        {
            free(file);
            return NULL;
        }
        file->outpos = 0;
    }
    return file;
}



size_t _fwrite(cosnt char* buff,size_t size,size_t conut,MY_FILE* file)
{
    size_t ret = 0;
    if(file->OUTMODE == OUTN)i
    {     
    }
    else if(file->OUTMODE == OUTALL)
    {}
    else if(file->OUTMODE == OUTNOW)
    {}

}

void _fclose(const MY_FILE* filename)
{
   if(filename)close(filename->outpos);     
}
